import { queryCity, queryProvince} from '@/services/geo';

const Geo = {
  namespace: 'geo',
  state: {
  },
  effects: {
 
    *fetchProvince(_, { call, put }) {
      const response = yield call(queryProvince);
      if (response.success) {
        yield put({
          type: 'setProvince',
          payload: response.data,
        });
      }
    },

    *fetchCity({ payload }, { call, put }) {
      const response = yield call(queryCity, payload);
      if (response.success) { 
        yield put({
          type: 'setCity',
          payload: response.data,
        });
      }
    },
  },
  reducers: {

    setProvince(state, action) {
      return { ...state, provinceList: action.payload };
    },

    setCity(state, action) {
      return { ...state, cityList: action.payload };
    },
  },
};
export default Geo;
